﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
namespace SAP
{
    public partial class ChangePassword : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
            if (!IsPostBack)
            {
                
                //if (Request.Browser.Browser == "IE")
                //{
                //    this.Login1.Enabled = false;
                //    return;
                //}
                //if (User.Identity.IsAuthenticated == true)
                //{
                // //   Response.Redirect("Homepage.aspx");
                //    Response.Redirect("~/TimeSheet/WeekendTimeSheet.aspx");
                //}
            }
            
        }

        protected void btn_Ok_Click(object sender, ImageClickEventArgs e)
        {
            String oldPass = Password.Text;
            String newPass = NewPassword.Text;
            String confPass = ConfirmPassword.Text;
            if (newPass != confPass) {
                FailureText.Text = "New password and confirm password do not match";
                return;
            }
            MembershipUser user = Membership.GetUser(User.Identity.Name, false);
            try
            {
                if (user.ChangePassword(oldPass, newPass))
                {
                    FailureText.Text = "Password changed";
                }
                else
                    FailureText.Text = "Password change failed.";
            }
            catch (Exception ex) {
                FailureText.Text = "Password change failed. " + ex.Message;
            }
            
            //1.1 ok then change
        }
      
    }
}
